<template>
  <div>
    <!-- <div class="put">
      <label for="fist">优惠金额</label>
      <input type="text" id="first" placeholder="请填写金额" v-model="money">
    </div>-->
    <div class="put">
      <label for="lab">优惠劵名</label>
      <input type="text" id="lab" placeholder="请填写优惠劵名字" v-model="couponName">
    </div>
    <!-- <div class="put">
      <label for="last">使用规则</label>
      <input type="text" id="last" placeholder="请填写使用规则" >
    </div>-->
    <div class="bottom-info">
      <div class="left">
        <label for>满：</label>
        <input
          type="text"
          v-validate="'required'"
          class="text-input"
          placeholder="请填写金额"
          v-model="miaoshu"
          name="reach1"
        >
      </div>
      <div class="right">
        <label for>减：</label>
        <input
          type="text"
          v-validate="'required'"
          class="text-input"
          placeholder="请填写金额"
          v-model="money"
          name="score1"
        >
      </div>
    </div>

    <!-- <div class="box_bom">
      <span>有效期至</span>
      <span @click="time()">{{acttime| formatDate('YYYY/MM/DD ')}}</span>
    </div> -->

    <!-- <mt-datetime-picker
      ref="picker"
      v-model="pickerVisible"
      type="date"
      year-format="{value} 年"
      month-format="{value} 月"
      date-format="{value} 日"
      @confirm="handleConfirm"
    ></mt-datetime-picker> -->

    <mt-datetime-picker ref="picker" type="date" v-model="pickerVisible" @confirm="handleConfirm"></mt-datetime-picker>

    <div class="bombtn">
      <router-link to @click.native="tijiao()">提交</router-link>
    </div>
  </div>
</template>

<script>
import { DatetimePicker } from "mint-ui";
export default {
  components: {
    [DatetimePicker.name]: DatetimePicker
  },
  data() {
    return {
      id: "",
      reach1: "",
      score1: "",
      pickerVisible: "",
      acttime:new Date(),
      miaoshu: "",
      qixian: "",
      couponName: "",
      money: "",
      host:0,
      timestamp1:''
    };
  },
  mounted() {
    this.info();
  },
  methods: {
    time() {
      this.$refs.picker.open();
    },
    handleConfirm(t) {
      var d = new Date(t);
      var youWant =d.getFullYear() +"/" +(d.getMonth() + 1) + "/" +d.getDate() 
         
        console.log(youWant)
    //   this.acttime = youWant.substring(0, youWant.length - 5);
       this.acttime = Date.parse(youWant);
      console.log(this.acttime);
      // alert(this.acttime)
    },
    info() {
      this.id = this.$route.query.id;
      if (this.id == undefined || this.id == null || this.id == "") {

      } else {
          this.host=1
        this.miaoshu = this.$route.query.miaoshu / 100;
        this.acttime = this.$route.query.qixian;
        console.log(this.acttime)
        this.couponName = this.$route.query.couponName;
        this.money = this.$route.query.money / 100;
        console.log(
          this.id,
          this.miaoshu,
          this.qixian,
          this.couponName,
          this.money
        );
      }
    },
    tijiao(){
      // alert(this.acttime)
        console.log(this.host)
        if(this.host==1){
            console.log('编辑')
           if(this.couponName==''){
               layer.msg('请填写优惠劵名字')
           }else if(this.money==''){
             layer.msg('请填写优惠金额')
           }else{
               var money=this.money*100
               var miaoshu=this.miaoshu*100
            //    console.log(this.acttime)
               this.$http.put(this.APIURL_PREFIX+"/api/wap/coupon",$.param({id:this.id,couponName:this.couponName,score1:money,reach1:miaoshu})).then((response) => {
                console.log(response)
                console.log(response.data.code)
                if(response.data.code==0){
                    this.$router.push({path:'me_favorable'})
                }
               })
           }

        }else{
            console.log('新增')
               if(this.couponName==''){
               layer.msg('请填写优惠劵名字')
           }else if(this.money==''){
             layer.msg('请填写优惠金额')
           }else{
                var money=this.money*100
               var miaoshu=this.miaoshu*100
                this.$http.post(this.APIURL_PREFIX+"/api/wap/staffCoupon",$.param({couponName:this.couponName,score1:money,reach1:miaoshu})).then((response) => {
                console.log(response)
                  if(response.data.code==0){
                    this.$router.push({path:'me_favorable'})
                }
               }) 
           }
            
        }
    }
  }
};
</script>

<style scoped>
@import "../../assets/personal/css/me_juanbianji.css";
</style>
